package cn.atzxc.qy.controller;

import cn.atzxc.qy.domain.ResponseResult;
import cn.atzxc.qy.domain.User;
import cn.atzxc.qy.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录方式：
 *  1.微信一键登录，不需要密码
 *  2.手机号密码登录，需要密码
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginService loginService;
    //微信一键登录
    @GetMapping("/weixinLogin")
    public ResponseResult weixinLogin(@RequestParam("code") String code) {
        ResponseResult responseResult = loginService.weixinLogin(code);
        return responseResult;
    }

    //账号密码登录
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        System.out.println("进拉拉二");
        ResponseResult login = loginService.login(user);
        return login;
    }


    @RequestMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }
}
